package com.shop.admin.controller;


import com.shop.Result.LdbzResult;
import com.shop.admin.service.AdminAuthService;
import com.shop.pojo.LdbzAdminAuth;
import com.shop.utils.ConvertUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/auth/service")
public class AdminAuthController {

    private static final Logger logger = LoggerFactory.getLogger(AdminAuthController.class);

    @Autowired
    private AdminAuthService adminAuthService;

    @RequestMapping(value = "/selectUserByRole", method = RequestMethod.GET)
    public LdbzResult selectUserByRole(Long roleId, int page, int limit, @RequestParam(value = "realName", defaultValue = "") String name) {
        return adminAuthService.selectUserByRole(roleId, page, limit, ConvertUtils.getKey(name));
    }

    @RequestMapping(value = "/selectMenuByRole", method = RequestMethod.GET)
    public LdbzResult selectMenuByRole(Long roleId, int page, int limit, @RequestParam(value = "menuName", defaultValue = "") String menuName) {
        return adminAuthService.selectMenuByRole(roleId, page, limit, ConvertUtils.getKey(menuName));
    }

    @RequestMapping(value = "/deleteByUser", method = RequestMethod.GET)
    public LdbzResult deleteByUser(Long userId, Long roleId) {
        return adminAuthService.deleteByUser(userId, roleId);
    }

    @RequestMapping(value = "/deleteByMenu", method = RequestMethod.GET)
    public LdbzResult deleteByMenu(Long menuId, Long roleId) {
        return adminAuthService.deleteByMenu(menuId, roleId);
    }

    @RequestMapping(value = "/insertByUser", method = RequestMethod.GET)
    public LdbzResult insertByUser(LdbzAdminAuth entity) {
        return adminAuthService.insertByUser(entity);
    }

    @RequestMapping(value = "/insertByMenu", method = RequestMethod.GET)
    public LdbzResult insertByMenu(LdbzAdminAuth entity) {
        return adminAuthService.insertByMenu(entity);
    }

    @RequestMapping(value = "/getUserByNameOrAccount", method = RequestMethod.GET)
    public LdbzResult getUserByNameOrAccount(String queryKey) {
        return adminAuthService.getUserByNameOrAccount(ConvertUtils.getKey(queryKey));
    }

    @RequestMapping(value = "/getResByNameOrUrl", method = RequestMethod.GET)
    public LdbzResult getResByNameOrUrl(String queryKey) {
        return adminAuthService.getResByNameOrUrl(ConvertUtils.getKey(queryKey));
    }

    @ResponseBody
    @RequestMapping(value = "/admin/auth/service/selectUserByRole", method = RequestMethod.GET)
    public LdbzResult selectUserByRole(Long roleId, int page, int limit,
                                       @RequestParam(value = "realName", defaultValue = "") String name) {
        return adminAuthService.selectUserByRole(roleId, page, limit, ConvertUtils.getKey(name));
    }
}
